/*
 * Copyright (c) 2011 Team A CS2340. All rights reserved.
 */

// TODO re-enable audit
// $codepro.audit.disable
package edu.gatech.teama.doctorsoffice.client.view;

import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JLabel;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;

import edu.gatech.teama.doctorsoffice.client.presenter.LoginPresenter;

import java.awt.Font;
import net.miginfocom.swing.MigLayout;

import javax.swing.JRootPane;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import javax.swing.BoxLayout;

import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import javax.swing.border.LineBorder;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

/**
 * LoginPanel.java
 * @author unknown
 * @version 1.0
 */
public class LoginPanel extends JPanel {
	
	/**
	 * myPresenter
	 */
	private LoginPresenter myPresenter;
	
	/**
	 * usernameTextField
	 */
	private JTextField usernameTextField;
	private JPasswordField pwd;

	/**
	 * Create the panel.
	 */
	public LoginPanel() {
		myPresenter = new LoginPresenter();
		
		setLayout(new MigLayout("", "[grow]", "[grow]"));
		
		JPanel panel = new JPanel();
		panel.setMinimumSize(new Dimension(400, 0));
		panel.setBorder(new LineBorder(new Color(0, 0, 0)));
		add(panel, "cell 0 0,alignx center,aligny center");
		panel.setLayout(new MigLayout("", "[61px][grow]", "[16px][][][][]"));
		
		JLabel lblDoctorsOffice = new JLabel("Doctor's Office");
		lblDoctorsOffice.setFont(new Font("Lucida Grande", Font.PLAIN, 20));
		panel.add(lblDoctorsOffice, "cell 0 0 2 1,alignx center,aligny top");
		
		JLabel lblTeamA = new JLabel("Team A");
		panel.add(lblTeamA, "cell 0 1 2 1,alignx center");
		
		JLabel lblUsername = new JLabel("Username:");
		panel.add(lblUsername, "cell 0 2,alignx trailing");
		
		usernameTextField = new JTextField();
		panel.add(usernameTextField, "cell 1 2,growx");
		usernameTextField.setColumns(10);
		
		JLabel lblPassword = new JLabel("Password:");
		panel.add(lblPassword, "cell 0 3,alignx trailing");
		
		pwd = new JPasswordField();
		panel.add(pwd, "cell 1 3,growx");
		
		JButton btnNewButton = new JButton("Login");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				myPresenter.login(usernameTextField.getText(), new String(pwd.getPassword()));
			}
		});
		panel.add(btnNewButton, "cell 1 4,alignx right");

	}
}
